package com.sbc.Flow;

import java.util.concurrent.Flow;

/**
 * @description: 自定义订阅者
 * @author: songbaicheng
 * @create: 2024-07-30 18:00
 **/
public class SimpleSubscriber<T> implements Flow.Subscriber<T> {

    @Override
    public void onSubscribe(Flow.Subscription subscription) {

        System.out.println("消费者请求数据");
        subscription.request(Long.MAX_VALUE);
    }

    @Override
    public void onNext(T item) {
        System.out.println("消费者收到的数据是: " + item);
    }

    @Override
    public void onError(Throwable throwable) {
        System.err.println("遇到错误了: " + throwable.getMessage());
    }

    @Override
    public void onComplete() {
        System.out.println("成功了！");
    }
}
